// 业务逻辑的api
import request from '../util/request.js'
// 连接api
const manapi = {
  User: '/admin/user',
  Role: '/admin/role',
  Article: '/admin/article',
  ArticleType: '/admin/articletype'
}

// 获取用户列表
export function getUserlist () {
  return request({
    url: manapi.User,
    method: 'GET'
  })
}

// 添加用户
export function addUser (userinfo) {
  return request({
    url: manapi.User,
    method: 'POST',
    data: userinfo
  })
}

export function delUser (id) {
  return request({
    url: manapi.User,
    method: 'DELETE',
    data: {
      userid: id
    }
  })
}

// 获取角色列表
export function getRole () {
  return request({
    url: manapi.Role,
    method: 'GET'
  })
}

// 获取文章列表
export function getArticle () {
  return request({
    url: manapi.Article,
    method: 'GET'
  })
}

// 获取文章类别
export function getArticleType () {
  return request({
    url: manapi.ArticleType,
    method: 'GET'
  })
}

// 添加文章
export function addArticle (article) {
  return request({
    url: manapi.Article,
    method: 'POST',
    data: article
  })
}

// 删除文章
export function delArticle (articleID) {
  return request({
    url: `${manapi.Article}?articleid=${articleID}`,
    method: 'delete'
  })
}
// 根据id获取文章详情
export function getArticleConById (articleId) {
  return request({
    url: `/admin/articleById?articleid=${articleId}`,
    method: 'get'
  })
}

// 添加分类
export function addType (type) {
  return request({
    url: '/admin/articletype',
    method: 'post',
    data: { type: type }
  })
}
